﻿using AdverseEventReportSystem.BLL.Escort;
using AdverseEventReportSystem.BLL.EscortManageSys;
using AdverseEventReportSystem.Core;
using AdverseEventReportSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace AdverseEventReportSystem.Web.Areas.Escort.Controllers
{
    public class TrajectoryHistoryController : BaseController
    {
        //
        // GET: /Escort/TrajectoryHistory/
        public ActionResult Index()
        {
            EscortManageSysSoapClient service = new EscortManageSysSoapClient();
            ResultHelperOfString serviceResult = service.GetAllParameterDict();
            if (serviceResult.S)
            {
                DataTable jsonobj = JsonHelper.ToDataTable(serviceResult.D);
                DataRow row = jsonobj.Select(" PARA_NAME = 'TEMPERATURE_ALERT_NUM' ")[0];
                ViewBag.dis_temper = row["DEFAULT_VALUE"].ToString();
            }
            ViewBag.CurrDepCode = loginUser.CurrDepCode;
            ViewBag.JobTitle = loginUser.JobTitle;
            return View();
        }

        public ActionResult Search()
        {
            int pageIndex = WebUtils.GetInt("page", 1);
            int pageSize = WebUtils.GetInt("pageSize", ConfigHelper.GetConfigInt("pagesize"));
            string date = WebUtils.GetString("date");
            string departmentCode = WebUtils.GetString("departmentCode");
            if (departmentCode == "-1") departmentCode = "";
            int tiwenzhuangtai = WebUtils.GetInt("tiwenzhuangtai");
            int sfxc = WebUtils.GetInt("sfxc");
            EscortManageSysSoapClient service = new EscortManageSysSoapClient();
            ResultHelperOfString serviceResult = service.SearchEscortTempList(date, departmentCode, tiwenzhuangtai, sfxc, pageIndex, pageSize);
            if (serviceResult.S)
            {
                var jsonobj = JsonConvert.DeserializeObject<dynamic>(serviceResult.D);
                var result = new { Total = jsonobj.total, Rows = jsonobj.data };
                return JsonDate(result);
            }

            return JsonDate(new { Total = 0, Rows = new DataTable() });
        }
    }
}